package com.woniu.rabbit.simple_model.consumer;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/consumer")
@RestController
@Slf4j
@Api(tags ="消费者")
public class SimpleConsumer {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    /**
     * 消费者
     * */
    @GetMapping(value = "/simple_hand")
    @ApiOperation("简单模式消费者--手动消费")
    public ResponseEntity receiveHand(){
        log.info("消费者接收到消息：{}");
        Object o = rabbitTemplate.receiveAndConvert("simple.queue");   // 传入队列名称
        return ResponseEntity.ok("消费消息成功：");
    }

    @ApiOperation("简单模式消费者--自动消费")
    @RabbitListener(queues = "simple.queue") // 指定监听的队列
    public void receiveAuto(String msg){
        log.info("消费者接收到消息：{}"+msg);
    }

}
